<!DOCTYPE html>
<html lang="en" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>G4F - Git Installation Guide</title>
    <link rel="apple-touch-icon" sizes="180x180" href="/dist/img/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/dist/img/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/dist/img/favicon-16x16.png">
    <link rel="manifest" href="/dist/img/site.webmanifest">
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/light-74231a1f3bbb.css" />
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/dark-8a995f0bacd4.css" />
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-primitives-225433424a87.css" />
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-b8b91660c29d.css" />
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-205098e9fedd.css" />
    <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-177d21388df8.css" />
    <style>
        :root {
            --colour-1: #000000;
            --colour-2: #ccc;
            --colour-3: #e4d4ff;
            --colour-4: #f0f0f0;
            --colour-5: #181818;
            --colour-6: #242424;
            --accent: #8b3dff;
            --gradient: #1a1a1a;
            --background: #16101b;
            --size: 70vw;
            --top: 50%;
            --blur: 40px;
            --opacity: 0.6;
        }

        /* Body and text color */
        body {
            height: 100vh;
            margin: 0;
            padding: 0;
        }

        .hidden {
            display: none;
        }

        .container-lg {
            margin: 0 auto;
            padding: 8px;
        }

        @media only screen and (min-width: 40em) {
            .container-lg {
                max-width: 84%;
            }
        }
    </style>
</head>
<body>
    <article class="markdown-body entry-content container-lg" itemprop="text"><div class="markdown-heading"><h2 class="heading-element">G4F - Git Installation Guide</h2><a id="user-content-g4f---git-installation-guide" class="anchor" aria-label="Permalink: G4F - Git Installation Guide" href="#g4f---git-installation-guide"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p>This guide provides step-by-step instructions for installing G4F from the source code using Git.</p>
<div class="markdown-heading"><h2 class="heading-element">Table of Contents</h2><a id="user-content-table-of-contents" class="anchor" aria-label="Permalink: Table of Contents" href="#table-of-contents"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<ol>
<li><a href="#prerequisites">Prerequisites</a></li>
<li>
<a href="#installation-steps">Installation Steps</a>
<ol>
<li><a href="#1-clone-the-repository">Clone the Repository</a></li>
<li><a href="#2-navigate-to-the-project-directory">Navigate to the Project Directory</a></li>
<li><a href="#3-set-up-a-python-virtual-environment-recommended">Set Up a Python Virtual Environment</a></li>
<li><a href="#4-activate-the-virtual-environment">Activate the Virtual Environment</a></li>
<li><a href="#5-install-dependencies">Install Dependencies</a></li>
<li><a href="#6-verify-installation">Verify Installation</a></li>
</ol>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#troubleshooting">Troubleshooting</a></li>
<li><a href="#additional-resources">Additional Resources</a></li>
</ol>
<hr>
<div class="markdown-heading"><h2 class="heading-element">Prerequisites</h2><a id="user-content-prerequisites" class="anchor" aria-label="Permalink: Prerequisites" href="#prerequisites"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p>Before you begin, ensure you have the following installed on your system:</p>
<ul>
<li>Git</li>
<li>Python 3.7 or higher</li>
<li>pip (Python package installer)</li>
</ul>
<div class="markdown-heading"><h2 class="heading-element">Installation Steps</h2><a id="user-content-installation-steps" class="anchor" aria-label="Permalink: Installation Steps" href="#installation-steps"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<div class="markdown-heading"><h3 class="heading-element">1. Clone the Repository</h3><a id="user-content-1-clone-the-repository" class="anchor" aria-label="Permalink: 1. Clone the Repository" href="#1-clone-the-repository"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>Open your terminal and run the following command to clone the G4F repository:</strong></p>
<div class="highlight highlight-source-shell"><pre>git clone https://github.com/xtekky/gpt4free.git</pre></div>
<div class="markdown-heading"><h3 class="heading-element">2. Navigate to the Project Directory</h3><a id="user-content-2-navigate-to-the-project-directory" class="anchor" aria-label="Permalink: 2. Navigate to the Project Directory" href="#2-navigate-to-the-project-directory"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>Change to the project directory:</strong></p>
<div class="highlight highlight-source-shell"><pre><span class="pl-c1">cd</span> gpt4free</pre></div>
<div class="markdown-heading"><h3 class="heading-element">3. Set Up a Python Virtual Environment (Recommended)</h3><a id="user-content-3-set-up-a-python-virtual-environment-recommended" class="anchor" aria-label="Permalink: 3. Set Up a Python Virtual Environment (Recommended)" href="#3-set-up-a-python-virtual-environment-recommended"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>It's best practice to use a virtual environment to manage project dependencies:</strong></p>
<div class="highlight highlight-source-shell"><pre>python3 -m venv venv</pre></div>
<div class="markdown-heading"><h3 class="heading-element">4. Activate the Virtual Environment</h3><a id="user-content-4-activate-the-virtual-environment" class="anchor" aria-label="Permalink: 4. Activate the Virtual Environment" href="#4-activate-the-virtual-environment"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>Activate the virtual environment based on your operating system:</strong></p>
<ul>
<li>
<p><strong>Windows:</strong></p>
<div class="highlight highlight-source-shell"><pre>.<span class="pl-cce">\v</span>env<span class="pl-cce">\S</span>cripts<span class="pl-cce">\a</span>ctivate</pre></div>
</li>
<li>
<p><strong>macOS and Linux:</strong></p>
<div class="highlight highlight-source-shell"><pre><span class="pl-c1">source</span> venv/bin/activate</pre></div>
</li>
</ul>
<div class="markdown-heading"><h3 class="heading-element">5. Install Dependencies</h3><a id="user-content-5-install-dependencies" class="anchor" aria-label="Permalink: 5. Install Dependencies" href="#5-install-dependencies"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>You have two options for installing dependencies:</strong></p>
<div class="markdown-heading"><h4 class="heading-element">Option A: Install Minimum Requirements</h4><a id="user-content-option-a-install-minimum-requirements" class="anchor" aria-label="Permalink: Option A: Install Minimum Requirements" href="#option-a-install-minimum-requirements"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>For a lightweight installation, use:</strong></p>
<div class="highlight highlight-source-shell"><pre>pip install -r requirements-min.txt</pre></div>
<div class="markdown-heading"><h4 class="heading-element">Option B: Install All Packages</h4><a id="user-content-option-b-install-all-packages" class="anchor" aria-label="Permalink: Option B: Install All Packages" href="#option-b-install-all-packages"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>For a full installation with all features, use:</strong></p>
<div class="highlight highlight-source-shell"><pre>pip install -r requirements.txt</pre></div>
<div class="markdown-heading"><h3 class="heading-element">6. Verify Installation</h3><a id="user-content-6-verify-installation" class="anchor" aria-label="Permalink: 6. Verify Installation" href="#6-verify-installation"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p>You can now create Python scripts and utilize the G4F functionalities. Here's a basic example:</p>
<p><strong>Create a <code>g4f-test.py</code> file in the root folder and start using the repository:</strong></p>
<div class="highlight highlight-source-python"><pre><span class="pl-k">import</span> <span class="pl-s1">g4f</span>
<span class="pl-c"># Your code here</span></pre></div>
<div class="markdown-heading"><h2 class="heading-element">Usage</h2><a id="user-content-usage" class="anchor" aria-label="Permalink: Usage" href="#usage"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>After installation, you can start using G4F in your Python scripts. Here's a basic example:</strong></p>
<div class="highlight highlight-source-python"><pre><span class="pl-k">import</span> <span class="pl-s1">g4f</span>

<span class="pl-c"># Your G4F code here</span>
<span class="pl-c"># For example:</span>
<span class="pl-k">from</span> <span class="pl-s1">g4f</span>.<span class="pl-s1">client</span> <span class="pl-k">import</span> <span class="pl-v">Client</span>

<span class="pl-s1">client</span> <span class="pl-c1">=</span> <span class="pl-en">Client</span>()

<span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-s1">client</span>.<span class="pl-c1">chat</span>.<span class="pl-c1">completions</span>.<span class="pl-c1">create</span>(
    <span class="pl-s1">model</span><span class="pl-c1">=</span><span class="pl-s">"gpt-4o-mini"</span>,
    <span class="pl-s1">messages</span><span class="pl-c1">=</span>[
        {
            <span class="pl-s">"role"</span>: <span class="pl-s">"user"</span>,
            <span class="pl-s">"content"</span>: <span class="pl-s">"Say this is a test"</span>
        }
    ]
    <span class="pl-c"># Add any other necessary parameters</span>
)

<span class="pl-en">print</span>(<span class="pl-s1">response</span>.<span class="pl-c1">choices</span>[<span class="pl-c1">0</span>].<span class="pl-c1">message</span>.<span class="pl-c1">content</span>)</pre></div>
<div class="markdown-heading"><h2 class="heading-element">Troubleshooting</h2><a id="user-content-troubleshooting" class="anchor" aria-label="Permalink: Troubleshooting" href="#troubleshooting"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<p><strong>If you encounter any issues during installation or usage:</strong></p>
<ol>
<li>Ensure all prerequisites are correctly installed.</li>
<li>Check that you're in the correct directory and the virtual environment is activated.</li>
<li>Try reinstalling the dependencies.</li>
<li>Consult the <a href="/docs/">G4F documentation</a> for more detailed information.</li>
</ol>
<div class="markdown-heading"><h2 class="heading-element">Additional Resources</h2><a id="user-content-additional-resources" class="anchor" aria-label="Permalink: Additional Resources" href="#additional-resources"><span aria-hidden="true" class="octicon octicon-link"></span></a></div>
<ul>
<li><a href="https://github.com/xtekky/gpt4free">G4F GitHub Repository</a></li>
<li><a href="https://docs.python.org/3/tutorial/venv.html" rel="nofollow">Python Virtual Environments Guide</a></li>
<li><a href="https://pip.pypa.io/en/stable/" rel="nofollow">pip Documentation</a></li>
</ul>
<hr>
<p><strong><em>For more information or support, please visit the <a href="https://github.com/xtekky/gpt4free/issues">G4F GitHub Issues page</a>.</em></strong></p>
<hr>
<p><a href="/docs/">Return to Documentation</a></p>
</article>
</body>
</html>